from data_processing.decompression import upzip_file

import pandas as pd


class Merge:
    def __init__(self, zip_file, target_dir, merge_name, header_row=['Players Name', 'Passes', 'Assists', 'Shots', 'Goals', 'TKLs', 'INTs', 'Catches', 'Saves', 'Wins', 'Loses']):
        self.merge_name = merge_name
        self.zip_file = zip_file
        self.target_dir = target_dir
        self.header_row = header_row

    def merge_csv(self):
        file_list1, file_list2 = upzip_file(self.zip_file, self.target_dir)
        # 读取文件
        df1 = pd.read_csv(self.target_dir + file_list1)
        df2 = pd.read_csv(self.target_dir + file_list2)
        # 合并
        df = pd.concat([df1, df2])
        df_sum = df.groupby('Players Name')[self.header_row].sum()
        merge_name = 'D:\pyitem\soccer\data\merge_data\\' + self.merge_name
        # 保存合并后的文件
        df_sum.to_csv(merge_name, encoding='utf-8')
        return merge_name


if __name__ == "__main__":
    print(Merge(r"/data/zip_data/9-17.zip", r"D:\pyitem\soccer\data\9-17", '9-17.csv').merge_csv())
